<!DOCTYPE html>
<html lang="en">
<head>
    <title>网站信息</title>
    {% include 'admin/common/header.html' %}
    <link rel="stylesheet" href="{{ url_for('static', filename='admin/admin/css/other/user.css') }}"/>
</head>
<body class="pear-container">
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input id="id" name="id" value="{{ websiteInfo.id if websiteInfo }}" type="hidden">
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入网站名"
                               class="layui-input" value="{{ websiteInfo.name if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站域名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="domain" lay-verify="required" autocomplete="off" placeholder="请输入网站域名"
                                class="layui-input" value="{{ websiteInfo.domain if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">SEO关键词：</label>
                    <div class="layui-input-block">
                        <input type="text" name="keyword" lay-verify="required" autocomplete="off" placeholder="请输入SEO关键词"
                                class="layui-input" value="{{ websiteInfo.keyword if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站描述：</label>
                    <div class="layui-input-block">
                        <input type="text" name="description" lay-verify="required" autocomplete="off" placeholder="请输入网站描述"
                                class="layui-input" value="{{ websiteInfo.description if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">站长QQ：</label>
                    <div class="layui-input-block">
                        <input type="text" name="qq" lay-verify="required" autocomplete="off" placeholder="请输入站长QQ"
                                class="layui-input" value="{{ websiteInfo.qq if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站logo图片（默认）：</label>
                    <div class="layui-input-block">
                        <input type="text" name="logo" lay-verify="required" autocomplete="off" placeholder="请输入网站logo图片（默认）"
                                class="layui-input" value="{{ websiteInfo.logo if websiteInfo }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站logo图片（深色）：</label>
                    <div class="layui-input-block">
                        <input type="text" name="logoDark" lay-verify="required" autocomplete="off" placeholder="请输入网站logo图片（深色）"
                                class="layui-input" value="{{ websiteInfo.logo_dark if websiteInfo }}">
                    </div>
                </div>
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="website-info-save">
                        <i class="layui-icon layui-icon-ok"></i>
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-sm">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </div>
    </div>
</form>
</body>

{% include 'admin/common/footer.html' %}

<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery
    form.on('submit(website-info-save)', function (data) {
      let roleIds = ''
      $('input[type=checkbox]:checked').each(function () {
        roleIds += $(this).val() + ','
      })
      roleIds = roleIds.substr(0, roleIds.length - 1)
      data.field.roleIds = roleIds

      $.ajax({
        url: '/admin/website_info/update',
        data: JSON.stringify(data.field),
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        },
        error: function (request) {
            layer.msg('网络错误', { icon: 2, time: 1000 })
        }

      })

      return false
    })
  })
</script>
</html>